/**
 * 后台操作日志
 */
var operLogUI = function() {
    var self = this;
    PageList.call(self);
};
operLogUI.prototype = Object.create(PageList.prototype);

operLogUI.registerPopover = function(td, index, list) {
    var data = list[index];
    td.popover({
        content: operLogUI.convertUri(data.uri) + "<br/>" + operLogUI.convertDetail(data),
        trigger: "hover",
    });
}

operLogUI.registerIp = function(ip) {
    CMD.ip_info(ip, function(r) {
        var arr = $("td.ip");
        for (var i = 0; i < arr.length; i++) {
            if ($(arr[i]).html() == ip) {
                $(arr[i]).html(ip + "(" + r.addr + ")");
            }
        }
    });
}

operLogUI.convertUri = function(uri) {
    switch (uri) {
        case "/bet/reopen": return "重新开奖";
        case "/bet/cancel": return "注单撤销";
        case "/notice/delete": return "删除消息";
        case "/notice/save": return "保存消息";
        case "/lottery/save": return "设置开奖结果";
        case "/account/log/pass": return "通过审核(账变记录)";
        case "/account/log/reject": return "拒绝(账变记录)";
        case "/user/crosier/saves": return "修改权限";
        case "/user/crosier/deletes": return "删除权限";
        case "/user/grade": return "修改用户角色";
        case "/user/reset-pass": return "重置密码";
        case "/lottery/rate/saves": return "保存赔率";
        case "/lottery/rate/backs": return "保存返水";
        case "/lottery/rate/ranges": return "保存投注限额";
        case "/account/log/dwpass": return "通过审核(打水余额)";
        case "/account/log/dwreject": return "拒绝(打水余额)";
        case "/account/log/gpass": return "群指令";
        case "/user/state": return "修改用户状态";
        case "/lottery/rate/rsaves": return "设置代理赔率";
        case "/lottery/rate/rbacks": return "设置代理返水";
    }
    return uri;
}

operLogUI.convertDetail = function(data) {
    var uri = data.uri,
        params = data.context.parameter;
    var content = '';

    switch (uri) {
        case '/lottery/save':
            content += get_game_display_name(params.type) + "第" + params.issue + '期<br/>';
            content += "开奖结果：" + params.red;
            break;

        case '/user/state':
            content += "用户ID：" + params.id + "<br/>";
            content += "目标状态：" + params.state;
            break;

        case '/bet/reopen':
        case '/bet/cancel':
            content += get_game_display_name(params.type) + "第" + params.issue + '期'
            break;

        case '/notice/delete':
        case '/notice/save':
            content += "消息标题：" + data.content.subject + "<br/>";
            content += "消息内容：" + data.content.content;
            break;

        case "/account/log/pass":
        case "/account/log/reject":
            content += "类型：" + Util.convertLogType(data.content.type) + "<br/>";
            if (data.content.type == 'deposit') {
                content += '充值类型：' + Util.convertChannel(data.content.channel) + "<br/>";
            }
            content += "金额：" + (data.content.amount/100).toFixed(2) + "<br/>";
            content += "时间：" + (data.content.start) + "<br/>";
            content += "用户：" + data.content.user;
            break;

        case "/user/grade":
            content += "角色：" + Rights.roles[data.content.grade] + "<br/>";
            break;

        case "/user/reset-pass":
            content += "用户：" + data.content.mobile;
            break;

        case "/lottery/rate/saves": 
        case "/lottery/rate/backs": 
        case "/lottery/rate/ranges":
            content += "游戏：" + get_game_display_name(params.type);
            break;
    }

    return content;
}
